/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_WEB_SOCKET_MESSAGE_H
#define MK_WEB_SOCKET_MESSAGE_H
#include "MkUtil/MkTypes.h"

class MkApi CMkWebSocketMessage
{
public:
    typedef enum websocket_frame_type
    {
        ErrorFrame = 0xFF,
        CloseFrame = 0x08,
        InCompleteFrame = 0x81,
        TextFrame = 0x01,
        BinaryFrame = 0x02,
        PingFrame = 0x09,
        PongFrame = 0x0A
    }MkWebSocketFrameType;
public:
    CMkWebSocketMessage();
    virtual ~CMkWebSocketMessage();
    void SetMark(BOOL bMask);
    void SetFrameType(const MkWebSocketFrameType& FrameType) { m_Opcode = FrameType; }
    Uint32 AddContent(const Uint8* pBuf, Uint32 nLen, OUT Uint32& nUsed);
    const Int8* GetPayloadData() const { return m_pPayloadData; }
    Uint64 GetPayloadLength() const { return m_PayloadLenth; }
    void SetPayloadData(const Int8* pPayloadData, Uint64 PayloadLen) { m_pPayloadData = pPayloadData;  m_PayloadLenth = PayloadLen; }
    Uint32 PacketHeader(Uint64 PayloadLen, MkString& Header);
    Uint32 PacketContent(const MkString& Content, MkString& Out);
    const Uint8& Fin() const { return m_Fin; }
    const Uint8& Reserved() const { return m_Reserved; }
    const MkWebSocketFrameType& Opcode() const { return m_Opcode; }
    const Uint8& Mask() const { return m_Mask; }
protected:
private:
    Uint8                               m_Fin;
    Uint8                               m_Reserved;
    MkWebSocketFrameType                m_Opcode;
    Uint8                               m_Mask;
    Uint64                              m_PayloadLenth;
    Uint32                              m_MaskingKey;
    const Int8                          *m_pPayloadData;

};


#endif